home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Ahoy 1987 July
/
Ahoy_Magazine_87-07_1987_Double_L_Side_A.d64
/
Binary Power 2
(
.txt
)
< prev
next >
Wrap
Commodore BASIC
|
2022-10-26
|
946b
|
29 lines
0 rem << cd43-6 >>
1 rem ==================================
2 rem commodares problem #39-3 :
3 print"[147] [194]inary [208]ower 2"
4 rem solution by
5 rem paul sobolik
6 rem ==================================
10 dim pw(7):for i=0to7:read pw(i):next
20 ml=5152:for x=0 to 10:read by:poke ml+x,by:next
30 n$="":input"enter no.";n$:n1=val(n$):if n$="end" then end
40 poke 251,n1:sys ml:n2=peek(252):p=n1:gosub 60:b1$=p$:p=n2:gosub 60:b2$=p$
50 print :print n1,b1$,b2$,n2:print:goto 30
60 p$="":for i=7 to 0 step -1:i$="0":if(p and pw(i)) then i$="1"
70 p$=p$+i$:next:return
80 data 1,2,4,8,16,32,64,128
81 rem =================================
82 rem $fb holds the number to be
83 rem reversed. asl left-shifts bit 7
84 rem into carry. ror right-rotates
85 rem carry into bit 7. y stores loop
86 rem count.
90 data 160,8 :rem ml ldy #$08
91 data 165,251 :rem lda $fb
92 data 42 :rem loop asl a
93 data 102,252 :rem ror $fc
94 data 136 :rem dey
95 data 208,250 :rem bne loop
96 data 96 :rem rts